#!/usr/bin/env node

const Koa=require('koa'),
      Router=require('koa-router'),
      bodyparse=require('koa-bodyparser');
const log=console.log,
      router=new Router(),
      app=new Koa();


router.get('/authors/',async (ctx,next)=>{
  var { page, limit }=ctx.query;

  log(`得到漫画书作者列表,page=${page},limit=${limit}`);
  ctx.body='查询成功';
})

router.get('/authors/:authorName',async (ctx,next)=>{
  var {authorName}=ctx.params;

  log(`按作者名查询,authorName=${authorName}`);
  ctx.body='查询成功';
})

router.post('/authors/',async (ctx,next)=>{
  var {authorName}=ctx.request.body;

  log(`添加新的漫画书作者,authorName=${authorName}`);
  ctx.body='添加成功';
})

router.put('/authors/:id',async (ctx,next)=>{
  var {id}=ctx.params;
  var {authorName}=ctx.request.body;

  log(`修改ID=${id}的漫画书作者名称,authorName=${authorName}`);
  ctx.body='修改成功'; 

})

router.delete('/authors/:id',async (ctx,next)=>{
  var {id}=ctx.params;

  log(`删除ID=${id}的漫画书作者`);//  /authors/\d
  ctx.body='删除成功';  
})


app.use(bodyparse({enableTypes:['json','form','text']}));

app.use(router.routes());
//app.use(bodyparse({enableTypes:['json','form','text']}));

app.listen(8080);













